using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace MicroMsg.UI.UserContrl
{
	public class SmileyViewDot : ContentControl
	{
		private static ImageSource SelectedImg = new ImageSourceConverter().ConvertFromString("/Resource/Img/Chat/smileyselect.png") as ImageSource;
		private static ImageSource NoSelectedImg = new ImageSourceConverter().ConvertFromString("/Resource/Img/Chat/smileynoselect.png") as ImageSource;
		private StackPanel DotListView;
		private int selectIndex;
		public static readonly DependencyProperty DotNumProperty = DependencyProperty.Register("DotNum", typeof(int), typeof(SmileyViewDot), new PropertyMetadata(3, new PropertyChangedCallback(SmileyViewDot.OnDotNumChanged)));
		private bool _contentLoaded;
		public int SelectIndex
		{
			get
			{
				return this.selectIndex;
			}
			set
			{
				if (value == this.selectIndex)
				{
					return;
				}
				this.SetImg(this.selectIndex, SmileyViewDot.NoSelectedImg);
				this.SetImg(value, SmileyViewDot.SelectedImg);
				this.selectIndex = value;
			}
		}
		public int DotNum
		{
			get
			{
				return (int)base.GetValue(SmileyViewDot.DotNumProperty);
			}
			set
			{
				base.SetValue(SmileyViewDot.DotNumProperty, value);
			}
		}
		public SmileyViewDot()
		{
			this.InitializeComponent();
		}
		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			this.DotListView = (base.GetTemplateChild("DotListView") as StackPanel);
			this.RefreshDotView();
		}
		private void SetImg(int index, ImageSource images)
		{
			if (this.DotListView == null)
			{
				return;
			}
			if (index >= this.DotListView.get_Children().get_Count() || index < 0)
			{
				return;
			}
			Image image = this.DotListView.get_Children().get_Item(index) as Image;
			if (image == null)
			{
				return;
			}
			image.set_Source(images);
		}
		private static void OnDotNumChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			SmileyViewDot smileyViewDot = dependencyObject_0 as SmileyViewDot;
			if (smileyViewDot == null)
			{
				return;
			}
			smileyViewDot.DotNumChanged(dependencyObject_0, dependencyPropertyChangedEventArgs_0);
		}
		public void DotNumChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_NewValue() == dependencyPropertyChangedEventArgs_0.get_OldValue())
			{
				return;
			}
			this.RefreshDotView();
		}
		private void RefreshDotView()
		{
			if (this.DotListView == null)
			{
				return;
			}
			if (this.DotNum <= 0)
			{
				return;
			}
			this.DotListView.get_Children().Clear();
			for (int i = 0; i < this.DotNum; i++)
			{
				Image image = new Image();
				image.set_Width(6.0);
				image.set_Height(6.0);
				image.set_Margin(new Thickness(6.0, 0.0, 6.0, 0.0));
				if (i == this.selectIndex)
				{
					image.set_Source(SmileyViewDot.SelectedImg);
				}
				else
				{
					image.set_Source(SmileyViewDot.NoSelectedImg);
				}
				this.DotListView.get_Children().Add(image);
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Chat/SmileyViewDot.xaml", 2));
		}
	}
}
